package com.lihua.project.system.score.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lihua.framework.aspectj.lang.annotation.Log;
import com.lihua.framework.aspectj.lang.enums.BusinessType;
import com.lihua.project.system.score.domain.TsScore;
import com.lihua.project.system.score.service.ITsScoreService;
import com.lihua.framework.web.controller.BaseController;
import com.lihua.framework.web.domain.AjaxResult;
import com.lihua.common.utils.poi.ExcelUtil;
import com.lihua.framework.web.page.TableDataInfo;

/**
 * 评分Controller
 * 
 * @author lihua
 * @date 2022-04-11
 */
@Controller
@RequestMapping("/system/score")
public class TsScoreController extends BaseController
{
    private String prefix = "system/score";

    @Autowired
    private ITsScoreService tsScoreService;

    @RequiresPermissions("system:score:view")
    @GetMapping()
    public String score()
    {
        return prefix + "/score";
    }

    /**
     * 查询评分列表
     */
    @RequiresPermissions("system:score:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TsScore tsScore)
    {
        startPage();
        List<TsScore> list = tsScoreService.selectTsScoreList(tsScore);
        return getDataTable(list);
    }

    /**
     * 导出评分列表
     */
    @RequiresPermissions("system:score:export")
    @Log(title = "评分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TsScore tsScore)
    {
        List<TsScore> list = tsScoreService.selectTsScoreList(tsScore);
        ExcelUtil<TsScore> util = new ExcelUtil<TsScore>(TsScore.class);
        return util.exportExcel(list, "评分数据");
    }

    /**
     * 新增评分
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评分
     */
    @RequiresPermissions("system:score:add")
    @Log(title = "评分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TsScore tsScore)
    {
        return toAjax(tsScoreService.insertTsScore(tsScore));
    }

    /**
     * 修改评分
     */
    @RequiresPermissions("system:score:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TsScore tsScore = tsScoreService.selectTsScoreById(id);
        mmap.put("tsScore", tsScore);
        return prefix + "/edit";
    }

    /**
     * 修改保存评分
     */
    @RequiresPermissions("system:score:edit")
    @Log(title = "评分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TsScore tsScore)
    {
        return toAjax(tsScoreService.updateTsScore(tsScore));
    }

    /**
     * 删除评分
     */
    @RequiresPermissions("system:score:remove")
    @Log(title = "评分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tsScoreService.deleteTsScoreByIds(ids));
    }
}
